﻿using System;
using System.Windows.Forms;
using KZ.Lottery.BLL;
using KZ.Lottery.Resources;

namespace KZ.Lottery
{
    public partial class FrmConnection : Form
    {
        public FrmConnection()
        {
            InitializeComponent();
        }

        private void btnBrowse_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                txtDatabase.Text = openFileDialog1.FileName;
            }
        }

        private void btnConnect_Click(object sender, EventArgs e)
        {
            string connStr = @"Server=.\SQLExpress;AttachDbFilename=" + txtDatabase.Text + ";Database=KZ.Lottery; Trusted_Connection=Yes;";
            Global.WriteConfig(connStr);
            if (SettingBLL.CheckConnection())
            {
                DialogResult = DialogResult.OK;
            }
            Global.SetMessage(lblMessage, KZ_Message.BLM_ERR_CONNECT, false);
        }

        private void FrmConnection_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (DialogResult != DialogResult.OK)
            {
                Application.Exit();
            }
        }
    }
}